package csc.training.jsf2.service;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ReferencedBean;
import javax.faces.bean.RequestScoped;

import com.sun.xml.internal.ws.developer.SchemaValidation;

import csc.training.jsf2.dao.Country_CityDaoImpl;
import csc.training.jsf2.entity.Country_City;

@ManagedBean(eager = true)
@RequestScoped
public class CountryCityServiceImpl implements CountryCityService {
	private Country_CityDaoImpl ccd;
	
	@Override
	public  List<String> getListCityByCountryName(String country) {
		// TODO Auto-generated method stub
		ccd = new Country_CityDaoImpl();
		List<Country_City> listCountryCity = ccd.getListCountryCity();
		for (Country_City c : listCountryCity) {
			if (c.getCountry().equals(country))
				return c.getCity();
		}
		return null;
	}

	@Override
	public List<String> getListCountry() {
		// TODO Auto-generated method stub
		ccd = new Country_CityDaoImpl();
		List<Country_City> listCountryCity = ccd.getListCountryCity();
		List<String> countryList = new ArrayList<String>();
		for (Country_City c : listCountryCity) {
			countryList.add(c.getCountry());
		}
		return countryList;
	}
}
